// index.js
import { createApp } from 'vue'
import toast from './toast.vue'

let instance

const initInstance = () => {
    const app = createApp(toast)
    const container = document.createElement('div')
    instance = app.mount(container)
    document.body.appendChild(container)
}

const Toast = option => {
    if (!instance) initInstance()
    const defaultOption = {
        message: '',
        duration: 2000,
    }
    option = typeof option === 'string' ? { message: option, duration: defaultOption.duration } : option

    for (const key in defaultOption) {
        instance[key] = option[key] || defaultOption[key]
    }

    return instance.open()
}

export default Toast;

